/**********************************************************************************************************
** 驱动文件：	ups-RT11K.c
** 驱动类型：	ups
** 设备名称：	UPS监测
** 设备型号：	RT11K
** 设备品牌：	中达电通
** 设备协议：	Delta UPS Protocol
** 驱动描述：	适用于中达电通RT系列单相不间断UPS电源
** 生成日期：	2019-11-08 22:36:58
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var InputFrequency;							//输入频率
	Var InputVoltage;							//输入电压
	Var OutputSource;							//UPS工作模式
	Var OutputFrequency;						//输出频率
	Var OutputVoltage;							//输出电压
	Var OutputCurrent;							//A想输出电流
	Var OutputPower;							//输出功率
	Var OutputLoad;								//输出负载率
	Var BypassFrequency;						//旁路频率
	Var BypassVoltage;							//旁路输入电压
	Var BypassCurrent;							//旁路输入电流
	Var BypassPower;							//旁路输入功率
	Var BatteryCondition;						//电池状况
	Var BatteryStatus;							//电池状态
	Var BatteryCharge;							//电池充电状态
	Var EstimatedMinutesRemaining;				//电池供电剩余时间
	Var BatteryVoltage;							//电池电压
	Var BatteryCurrent;							//电池电流
	Var BatteryLevel;							//电池电量
	Var UPSTemperature;							//UPS温度
	Var AlarmTemperature;						//温度报警
	Var AlarmInputBad;							//输入故障
	Var AlarmOutputBad;							//输出故障
	Var AlarmOverload;							//过载报警
	Var AlarmBypassBad;							//旁路故障报警
	Var AlarmOutputOff;							//输出关闭报警
	Var AlarmUPSShutdown;						//UPS关机报警
	Var AlarmChargerFailure;					//充电器故障
	Var AlarmStandby;							//系统待机
	Var AlarmFanFailure;						//风扇故障
	Var AlarmFuseFailure;						//保险故障
	Var AlarmOtherWarning;						//其它报警
	Var AlarmAwaitingPower;						//输出功率滞后
	Var AlarmShutdownPending;					//关机挂起报警
	Var AlarmShutdownImminent;					//即将关机报警
	Var BuzzerStatus;							//蜂鸣器报警
	Var EconomicMode;							//节能模式
	Var AlarmInverterBad;						//逆变器故障
	Var EmergencyPowerOff;						//紧急关机
	Var BatteryGroundFault;						//电池接地故障
	Var AlarmOutputVoltageOverLimit;			//输出电压过高报警
	Var AlarmOutputVoltageUnderLimit;			//输出电压过低报警
	Var AlarmPowerModule;						//电源模块报警
	Var OutputBreaker;							//输出断路器
	Var AlarmPhaseAsynchronous;					//相位异步报警
	Var AlarmRectifierAbnormal;					//整流器异常
	Var BypassBreaker;							//旁路断路器
	Var MainInputBreaker;						//市电输入断路器
	Var TestResult;								//UPS测试结果
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		FLOAT,
		0,
		READONLY,
		"InputFrequency",
		"输入频率",
		"Hz",
		"输入频率",
		0,
		0,
		"输入频率过高",
		"输入频率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"InputVoltage",
		"输入电压",
		"V",
		"输入电压",
		0,
		0,
		"输入电压过高",
		"输入电压过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutputSource",
		"UPS工作模式",
		"",
		"UPS输出源：0-市电供电、1-电池供电、2-旁路供电、3-降压供电、4-升压推免、5-手动旁路、6-其它、7-无输出、8-ECO节能",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputFrequency",
		"输出频率",
		"Hz",
		"输出频率",
		0,
		0,
		"输出频率过高",
		"输出频率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputVoltage",
		"输出电压",
		"V",
		"输出电压",
		0,
		0,
		"输出电压过高",
		"输出电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputCurrent",
		"A想输出电流",
		"",
		"A想输出电流",
		0,
		0,
		"A想输出电流过高",
		"A想输出电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputPower",
		"输出功率",
		"W",
		"输出功率",
		0,
		0,
		"输出功率过高",
		"输出功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputLoad",
		"输出负载率",
		"%",
		"输出负载率",
		0,
		0,
		"输出负载率过高",
		"输出负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassFrequency",
		"旁路频率",
		"Hz",
		"旁路频率",
		0,
		0,
		"旁路频率过高",
		"旁路频率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassVoltage",
		"旁路输入电压",
		"V",
		"旁路输入电压",
		0,
		0,
		"旁路输入电压过高",
		"旁路输入电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassCurrent",
		"旁路输入电流",
		"",
		"旁路输入电流",
		0,
		0,
		"旁路输入电流过高",
		"旁路输入电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassPower",
		"旁路输入功率",
		"W",
		"旁路输入功率",
		0,
		0,
		"旁路输入功率过高",
		"旁路输入功率过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryCondition",
		"电池状况",
		"",
		"电池状况：0-很好、1-虚弱、2-需要更换",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryStatus",
		"电池状态",
		"",
		"电池状态：0-电量很满、1-电量低、2-电量耗尽",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryCharge",
		"电池充电状态",
		"",
		"电池充电状态：0-浮充、1-均充、2-停止充电、3-电池放电",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"EstimatedMinutesRemaining",
		"电池供电剩余时间",
		"分",
		"电池供电剩余时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryVoltage",
		"电池电压",
		"V",
		"电池电压",
		0,
		0,
		"电池电压过高",
		"电池电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryCurrent",
		"电池电流",
		"",
		"电池电流",
		0,
		0,
		"电池电流过高",
		"电池电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryLevel",
		"电池电量",
		"%",
		"电池电量",
		0,
		0,
		"电池电量过高",
		"电池电量过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"UPSTemperature",
		"UPS温度",
		"℃",
		"UPS温度",
		0,
		0,
		"UPS温度过高",
		"UPS温度过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmTemperature",
		"温度报警",
		"",
		"温度报警：0-正常、2-高温报警",
		0,
		0,
		"高温报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmInputBad",
		"输入故障",
		"",
		"输入电压故障报警：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmOutputBad",
		"输出故障",
		"",
		"输出电压故障：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmOverload",
		"过载报警",
		"",
		"过载报警：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmBypassBad",
		"旁路故障报警",
		"",
		"旁路故障报警：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmOutputOff",
		"输出关闭报警",
		"",
		"输出关闭报警：0-输出打开、1-输出关闭",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmUPSShutdown",
		"UPS关机报警",
		"",
		"UPS关机报警：0-正常、1-关机",
		0,
		0,
		"关机",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmChargerFailure",
		"充电器故障",
		"",
		"充电器故障：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmStandby",
		"系统待机",
		"",
		"系统待机：0-运行、1-待机",
		0,
		0,
		"待机",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmFanFailure",
		"风扇故障",
		"",
		"风扇故障：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmFuseFailure",
		"保险故障",
		"",
		"保险故障：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmOtherWarning",
		"其它报警",
		"",
		"其它报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmAwaitingPower",
		"输出功率滞后",
		"",
		"输出功率滞后：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmShutdownPending",
		"关机挂起报警",
		"",
		"关机挂起报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmShutdownImminent",
		"即将关机报警",
		"",
		"即将关机报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BuzzerStatus",
		"蜂鸣器报警",
		"",
		"蜂鸣器报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EconomicMode",
		"节能模式",
		"",
		"节能模式：0-未启用、1-启用",
		0,
		0,
		"启用",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmInverterBad",
		"逆变器故障",
		"",
		"逆变器故障：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EmergencyPowerOff",
		"紧急关机",
		"",
		"紧急关机：0-正常运行、1-紧急关机",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryGroundFault",
		"电池接地故障",
		"",
		"电池接地故障：0-正常、1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmOutputVoltageOverLimit",
		"输出电压过高报警",
		"",
		"输出电压过高报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmOutputVoltageUnderLimit",
		"输出电压过低报警",
		"",
		"输出电压过低报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmPowerModule",
		"电源模块报警",
		"",
		"电源模块报警：0-正常、1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutputBreaker",
		"输出断路器",
		"",
		"输出断路器断开：0-闭合、1-断开",
		0,
		0,
		"断开报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmPhaseAsynchronous",
		"相位异步报警",
		"",
		"相位异步报警：0-正常同步、1-异步报警",
		0,
		0,
		"异步",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmRectifierAbnormal",
		"整流器异常",
		"",
		"整流器异常：0-正常、1-异常报警",
		0,
		0,
		"异常",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassBreaker",
		"旁路断路器",
		"",
		"旁路断路器断开：0-闭合、1-断开",
		0,
		0,
		"断开报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainInputBreaker",
		"市电输入断路器",
		"",
		"市电输入断路器：0-闭合、1-断开",
		0,
		0,
		"断开报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"TestResult",
		"UPS测试结果",
		"",
		"UPS测试结果：0-未执行测试、1-测试通过、2-测试中、3-一般测试失败、4-电池测试失败、5-电池深度放电测试失败、6-测试终止",
		0,
		0,
		"",
		"",
		0,
		0
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:
			*len = sprintf(cmd,"~00P003STI");
			break;
		case 1:
			*len = sprintf(cmd,"~00P003STO");
			break;
		case 2:
			*len = sprintf(cmd,"~00P003STP");
			break;
		case 3:
			*len = sprintf(cmd,"~00P003STB");
			break;
		case 4:
			*len = sprintf(cmd,"~00P003STA");
			break;			
		case 5:
			*len = sprintf(cmd,"~00P003TSR");			
			break;			
		default:
			break;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse(char **buf)
* 函数说明： 变量解析
* 输入参数： 变量字符串地址
* 返回参数： 返回解析结果
**********************************************************************************************************/
static int parse(char **buf)
{
	int ret;
	if(**buf==';'){
		(*buf)++;
		return 0;
	}
	else if(**buf>='0'&&**buf<='9'){
		ret = atoi(*buf);
		while(**buf!=';'&&**buf!='\0') (*buf)++;      
		if(**buf==';') (*buf)++;      
		return ret;
	}
	else{
		return 0;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	const char *OutputSource[]	= {"市电供电","电池供电","旁路供电","降压供电","升压推免","手动旁路","其它","无输出","ECO节能"};
	const char *TestResult[]	= {"未执行测试","测试通过","测试中","一般测试失败","电池测试失败","电池深度放电测试失败","测试终止"};
	const char *BatteryCondition[]	= {"很好","虚弱","需要更换"};	
	const char *BatteryStatus[]	= {"电量很满","电量低","电量耗尽"};
	const char *BatteryCharge[]	= {"浮充","均充","停止充电","电池放电"};	
	int   i;

	Data_Struct 	*d = (Data_Struct*)data;
	buf[len] = '\0';
	if(buf!=NULL && buf[0]=='~' && buf[1]=='0' && buf[2]=='0' && buf[3]=='D' && len>0)
	{
		buf[0] = buf[7];
		buf[7] = ';';
		if(atoi(buf+4)!=(len-7)) 	return 1;	//数据帧接收不完整
		buf[7] = buf[0];
		buf += 7;
		switch(index)
		{
			case 0:
				parse(&buf);
				d->InputFrequency.value.fnum		= parse(&buf)*0.1;
				d->InputVoltage.value.fnum			= parse(&buf)*0.1;
				break;
			case 1:
				d->OutputSource.value.str			= OutputSource[parse(&buf)];
				d->OutputFrequency.value.fnum		= parse(&buf)*0.1;
				parse(&buf);
				d->OutputVoltage.value.fnum			= parse(&buf)*0.1;
				d->OutputCurrent.value.fnum			= parse(&buf)*0.1;
				d->OutputPower.value.fnum			= parse(&buf)*1.0;
				d->OutputLoad.value.fnum			= parse(&buf)*1.0;
				break;
			case 2:
				d->BypassFrequency.value.fnum		= parse(&buf)*0.1;
				parse(&buf);
				d->BypassVoltage.value.fnum			= parse(&buf)*0.1;
				d->BypassCurrent.value.fnum			= parse(&buf)*0.1;
				d->BypassPower.value.fnum			= parse(&buf)*1.0;
				break;
			case 3:
				i = parse(&buf);
				d->BatteryCondition.value.str					= BatteryCondition[i];
				Set_Var_Status(&d->BatteryCondition,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->BatteryStatus.value.str						= BatteryStatus[i];
				Set_Var_Status(&d->BatteryStatus,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->BatteryCharge.value.str						= BatteryCharge[i];
//				Set_Var_Status(&d->BatteryCharge, i?Alarm:Normal, NULL);
				parse(&buf);
				d->EstimatedMinutesRemaining.value.inum			= parse(&buf);
				parse(&buf);
				d->BatteryVoltage.value.fnum			= parse(&buf)*0.1;
				d->BatteryCurrent.value.fnum			= parse(&buf)*0.1;
				d->UPSTemperature.value.fnum					= parse(&buf)*1.0;
				d->BatteryLevel.value.fnum				= parse(&buf)*1.0;
				break;				
			case 4:
				i = parse(&buf);
				d->AlarmTemperature.value.str =					i?"高温报警":"正常";
				Set_Var_Status(&d->AlarmTemperature,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmInputBad.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmInputBad,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmOutputBad.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmOutputBad,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmOverload.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmOverload,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmBypassBad.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmBypassBad,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmOutputOff.value.str =					i?"输出关闭":"输出打开";
				Set_Var_Status(&d->AlarmOutputOff,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmUPSShutdown.value.str =					i?"关机报警":"正常";
				Set_Var_Status(&d->AlarmUPSShutdown,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmChargerFailure.value.str =				i?"故障":"正常";
				Set_Var_Status(&d->AlarmChargerFailure,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmStandby.value.str =						i?"待机":"运行";
				Set_Var_Status(&d->AlarmStandby,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmFanFailure.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmFanFailure,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmFuseFailure.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmFuseFailure,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmOtherWarning.value.str =				i?"故障":"正常";
				Set_Var_Status(&d->AlarmOtherWarning,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmAwaitingPower.value.str =				i?"报警":"正常";
				Set_Var_Status(&d->AlarmAwaitingPower,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmShutdownPending.value.str =				i?"报警":"正常";
				Set_Var_Status(&d->AlarmShutdownPending,		i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmShutdownImminent.value.str =			i?"报警":"正常";
				Set_Var_Status(&d->AlarmShutdownImminent,		i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->BuzzerStatus.value.str =						i?"报警":"正常";
				Set_Var_Status(&d->BuzzerStatus,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->EconomicMode.value.str =						i?"启用":"未启用";
				Set_Var_Status(&d->EconomicMode,				i?ON:OFF, NULL);
				i = parse(&buf);
				d->AlarmInverterBad.value.str =					i?"故障":"正常";
				Set_Var_Status(&d->AlarmInverterBad,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->EmergencyPowerOff.value.str =				i?"紧急关机":"正常运行";
				Set_Var_Status(&d->EmergencyPowerOff,			i?Alarm:Normal, NULL);
				parse(&buf);
				i = parse(&buf);
				d->BatteryGroundFault.value.str =				i?"故障":"正常";
				Set_Var_Status(&d->BatteryGroundFault,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmOutputVoltageOverLimit.value.str =		i?"报警":"正常";
				Set_Var_Status(&d->AlarmOutputVoltageOverLimit,	i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmOutputVoltageUnderLimit.value.str =		i?"报警":"正常";
				Set_Var_Status(&d->AlarmOutputVoltageUnderLimit,i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmPowerModule.value.str =					i?"报警":"正常";
				Set_Var_Status(&d->AlarmPowerModule,			i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->OutputBreaker.value.str =					i?"断开":"闭合";
				Set_Var_Status(&d->OutputBreaker,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmPhaseAsynchronous.value.str =			i?"异步报警":"正常同步";
				Set_Var_Status(&d->AlarmPhaseAsynchronous,		i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->AlarmRectifierAbnormal.value.str =			i?"异常报警":"正常";
				Set_Var_Status(&d->AlarmRectifierAbnormal,		i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->BypassBreaker.value.str =					i?"断开":"闭合";
				Set_Var_Status(&d->BypassBreaker,				i?Alarm:Normal, NULL);
				i = parse(&buf);
				d->MainInputBreaker.value.str =					i?"断开":"闭合";
				Set_Var_Status(&d->MainInputBreaker,			i?Alarm:Normal, NULL);
				break;
			case 5:
				i = parse(&buf);
				d->TestResult.value.str =						TestResult[i];
				Set_Var_Status(&d->TestResult, (i==3||i==4||i==5)?Alarm:Normal, NULL);			
				break;				
			default:
				break;
		}
		return 0;
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void ups_RT11K_Registration(void)
* 函数说明： UPS监测驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void ups_RT11K_Registration(void)
{
	DeviceDriverRegistration(
		"ups",													//设备类型
		"UPS监测",												//设备名称（导航栏默认显示名称）
		"中达电通",												//设备品牌
		"RT11K",												//设备型号
		"适用于中达电通RT系列单相不间断UPS电源",				//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		1000													//设备响应超时时间
	);
#if 0 || VirtualFrameEN
	#define CMD1 "~00P003STI"
	#define RSP1 "~00D0101;500;2260"	
	#define CMD2 "~00P003STO"
	#define RSP2 "~00D0250;500;1;2190;118;2287;026"		
	#define CMD3 "~00P003STP"
	#define RSP3 "~00D019500;1;2260;000;0000"		
	#define CMD4 "~00P003STB"
	#define RSP4 "~00D0310;0;0;00000;0026;;2714;;022;100"
	#define CMD5 "~00P003STA"
	#define RSP5 "~00D0380;0;0;0;0;0;0;0;0;0;0;0;0;0;;0;0;0;0;1"		
	#define CMD6 "~00P003TSR"
	#define RSP6 "~00D0010"

	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);		
	VirtualFrameRegistration(CMD2, sizeof(CMD2)-1, RSP2, sizeof(RSP2)-1);		
	VirtualFrameRegistration(CMD3, sizeof(CMD3)-1, RSP3, sizeof(RSP3)-1);	
	VirtualFrameRegistration(CMD4, sizeof(CMD4)-1, RSP4, sizeof(RSP4)-1);
	VirtualFrameRegistration(CMD5, sizeof(CMD5)-1, RSP5, sizeof(RSP5)-1);	
	VirtualFrameRegistration(CMD6, sizeof(CMD6)-1, RSP6, sizeof(RSP6)-1);	
#endif	
}

